home *** CD-ROM | disk | FTP | other *** search
- PROCEDURE SFighter; {Stealth Fighter}
- {
- Author: David Malmberg
-
- Strategy: Move slowly around the field -- bouncing off of walls,
- obstructions, and other robots -- as necessary. If you find a foe,
- take a shot and keep improving aim and shooting until foe is
- lost from sights. Then move sights (scanning) to adjacent target
- area.
-
- When robot incurrs damage, raise cloak and move away. Keep cloak
- raised until robot has not had any damage for at least 3000 cycles.
- }
-
- (* Below are the SFighter options as specified in the SFIGHTER.CFG file
-
- Radar := 2; {Maximum range for robot's scanner -- 600 meters}
- Fuel := 2; {Maximum fuel for robot -- 1250 jiggers}
- Engine := 0; {Type of engine for robot -- Economy}
- Armor := 0; {Type of Armor for robot -- Light}
- Warheads := 1; {Type of Missile for robot -- Normal -- 700 meter range}
- Bombs := 0; {Determines the number of Bombs for robot}
- Shielding := 0; {Default -- Robot has Shielding}
- Cloaking := 5; {Default -- Robot has Cloaking}
- Repairing := 0; {Default -- Robot has NO Repair Kit}
-
- *)
-
- VAR { SFighter "Global" variables }
-
- Angle, { Scanning angle }
- Range, { Scanning range to foe -- hopefully! }
- Last_Damage, { Robot's Last damage value }
- D_Speed, { Robot's desired speed }
- D_Heading, { Robot's desired heading }
- LastTime, { Last Time cycles were measured }
- Delta : Integer; { Scanning arc }
-
-
- PROCEDURE Bounce;
- { If stopped, then move away at an angle. Designed to allow
- robot to "bounce" off of walls, obstructions and other robots. }
- BEGIN
- IF Speed = 0
- THEN BEGIN
- D_Heading := D_Heading + 120; { Bounce off at an angle }
- Drive(D_Heading, D_Speed);
- END;
- END; {Bounce}
-
-
- FUNCTION Hurt : Boolean;
- { Checks if Robot has incurred any new damage. }
- VAR Curr_Damage : Integer;
- Answer : Boolean;
- BEGIN
- Curr_Damage := damage;
- Answer := (Curr_Damage > Last_Damage);
- Last_Damage := Curr_Damage;
- IF Answer THEN LastTime := Time;
- Hurt := Answer;
- END; {Hurt}
-
-
- PROCEDURE Aim(VAR Ang : Integer; VAR Arc : Integer);
- {
- Improve aim by doing a binary search of the target area.
- I.E., divide the target area in two equal pieces and redefine
- the target area to be the piece where the foe is found.
- If the foe is not found, expand the search area to the
- maximum arc of plus or minus 10 degrees.
- }
- BEGIN
- Arc := Arc DIV 2; { Divide search area in two. }
- IF scan(Ang-Arc, Arc) <> 0 { Check piece "below" target angle. }
- THEN Ang := Ang-Arc { If foe found, redefine target angle. }
- ELSE IF scan(Ang+Arc, Arc) <> 0 { Check piece "above" target angle. }
- THEN Ang := Ang+Arc { If foe found, redefine target angle. }
- ELSE Arc := 10;
- { Foe not found in either piece, expand search area to maximum arc. }
- END; {Aim}
-
- BEGIN {SFighter Main}
- Angle := Angle_To(500, 500);
- D_Heading := Angle;
- D_Speed := 50;
- { Start scanning for foes and moving to center of field. }
- LowerCloak; { Start off with Cloak DOWN! }
- LastTime := Time;
- REPEAT { Until Dead or Winner }
- Bounce; { If stopped, move off at angle }
- IF Fuel < 250 THEN LowerCloak;
- IF NOT Hurt {If not hurt and no damage for 3000 cycles}
- THEN IF (Time > (LastTime + 3000))
- THEN BEGIN {Safe to lower cloak and slow down}
- LowerCloak;
- D_Speed := 50;
- END;
- Delta := 10; { Start with widest scanning arc. }
- Range := scan(Angle, Delta);
- WHILE (Range > 40) AND (ObjectScanned = Enemy) DO
- { Must be far enough away to avoid self-damage. }
- BEGIN
- Aim(Angle, Delta); { Improve aim. }
- Cannon(Angle, Range); { Fire!! }
- Range := scan(Angle, Delta); { Is foe still in sights? }
- END;
- Angle := Angle+20; { Look in adjacent target area. }
- IF Hurt THEN { Raise cloak and flee! }
- BEGIN
- IF Fuel > 250 THEN RaiseCloak;
- D_Heading := Angle + 180; { Run away from foe! }
- D_Speed := MaxSpeed;
- Drive(D_Heading, D_Speed);
- END;
- UNTIL Dead OR Winner;
- END; {SFighter Main}
-